package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Comparator;
import java.util.stream.Collectors;

/**
 * 有限小数数列
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexDecimalSeries extends LatexNumberSeries {
    private Collection<BigDecimal> values;

    public String getLatex() {
        return StringUtils.join(values, ",");
    }

    public LatexDecimalSeries(Collection<BigDecimal> values) {
        this.values = values;
    }

    public LatexDecimalSeries(String content) {
        this.values = ParseHelper.parseBigDecimal(content, ",");
    }

    public Collection<BigDecimal> ascSort() {
        var sortedList = values.stream().sorted();
        return sortedList.collect(Collectors.toList());
    }

    public Collection<BigDecimal> descSort() {
        var sortedList = values.stream().sorted(Comparator.reverseOrder());
        return sortedList.collect(Collectors.toList());
    }
}
